import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import fire from '@feidao/web/atom/browser/msg/fire';
import error from '@feidao/web/atom/browser/msgbox/error';
// import register from '@feidao/web/atom/browser/msg/user-regist';
// import { send_msg, systemid, spaceid } from './config';

////////////////////////////////////////////////////////////////////////////////
// import atoms
////////////////////////////////////////////////////////////////////////////////
export default async function a001(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	const user_name = fd.data.node.querySelector('[data-feidao-id="user_name"]') as HTMLInputElement;
	if (!user_name.value) {
		error('用户名不能为空!');
		return;
	} else {
		const user_name_regx = /^[a-zA-Z0-9]{6,21}$/
		if (!user_name_regx.test(user_name.value)) {
			error('您输入的账号不符合要求！请重新设置!');
			return;
		}
	}
	const user_pwd = fd.data.node.querySelector('[data-feidao-id="user_pwd"]') as HTMLInputElement;
	if (!user_pwd.value) {
		error('用户密码不能为空!');
		return;
	} else {
		const user_pwd_regx = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
		if (!user_pwd_regx.test(user_pwd.value)) {
			error('您输入的密码不符合要求！');
			return;
		}
	}
	const user_pwd_sure = fd.data.node.querySelector('[data-feidao-id="user_pwd_sure"]') as HTMLInputElement;
	if (!user_pwd_sure.value) {
		error('请再次输入密码!');
		return;
	} else {
		if (user_pwd_sure.value != user_pwd.value) {
			error('两次输入密码不一致!');
			return;
		}
		fd.data.node.classList.add('display-n')
		const name = { user_name: user_name.value, user_pwd: user_pwd.value };
		// 调用注册服务
		// const res = await register(send_msg, systemid, spaceid, user_name.value, '', false, '', '', user_pwd.value, '', 'usercode');
		fire('zj-000003', 'ec-001', name)
	}

}
